import env from "../config/env";
import util from "./http.util";
import { apiUrl } from "@/config/config";

let Service = {};

Service = {
  getRequest(url, param = {}) {
    if (url.indexOf("http") == -1) {
      url = apiUrl + url;
    }
    return util.ajax.get(url, {
      params: param
    }).then(res => {
      return new Promise((resolve, reject) => {
        resolve(res.data);
      });
    });
  },

  postRequest(url, param = {}) {
    if (url.indexOf("http") == -1) {
      url = apiUrl + url;
    }
    return util.ajax.post(url, param).then(res => {
      return new Promise((resolve, reject) => {
        resolve(res.data);
      });
    });
  },
  putRequest(url, param = {}) {
    if (url.indexOf("http") == -1) {
      url = apiUrl + url;
    }
    return util.ajax.put(url, param).then(res => {
      return new Promise((resolve, reject) => {
        resolve(res.data);
      });
    });
  },

  deleteRequest(url, param = {}) {
    if (url.indexOf("http") == -1) {
      url = apiUrl + url;
    }
    return util.ajax.delete(url, {
      data: param
    }).then(res => {
      return new Promise((resolve, reject) => {
        resolve(res.data);
      });
    });
  },

  path: {
    test: "/test",

    // user
    register: "/user/register",
    login: "/user/login",
    getAllUser:"/user/getAllUser",
    getUserInfo:"/user/getUserInfo",
    getAllDoctor:"/user/getAllDoctor",
    updUserInfo:"/user/updUserInfo",

    // instant message
    addConversation:"/conversation/addConversation",
    getConversation:"/conversation/getConversation",
    sendPrivateMsg:"/privateMsg/sendMsg",
    getPrivateMsg:"/privateMsg/getMsg",

    // diseaseType
    getDiseaseClass:"/diseaseType/getDiseaseClass",

    // disease
    getDiseaseByType:"/disease/getDiseaseByType",
    getDiseaseDetail:"/disease/getDiseaseDetail",
    getDiseaseMostPV:"/disease/getMostPV",

    // artical video live
    postArtical:"/artical/post",
    postVideo:"/video/post",
    getMostPV:"/artical/getMostPV",
    getArticalDetail:"/artical/getArticalDetail",
    getRecommend:"/artical/getRecommend",
    postLive:"/live/start",
    getLiveInfo:"/live/getDetail",
    getAllVideo:"/video/getAllVideo"
  },


  /**
   * artical video live
   */
  postArtical(params) {
    return this.postRequest(this.path.postArtical,params)
  },
  postVideo(params) {
    return this.postRequest(this.path.postVideo,params)
  },
  getMostPV() {
    return this.getRequest(this.path.getMostPV)
  },
  getArticalDetail(params) {
    return this.getRequest(this.path.getArticalDetail,params)
  },
  getRecommend() {
    return this.getRequest(this.path.getRecommend)
  },
  postLive(params) {
    return this.postRequest(this.path.postLive,params)
  },
  getLiveInfo(params) {
    return this.getRequest(this.path.getLiveInfo,params)
  },
  getAllVideo(params) {
    return this.getRequest(this.path.getAllVideo,params)
  },

  /**
   * diseaseType
   */
  getDiseaseClass(params) {
    return this.getRequest(this.path.getDiseaseClass,params)
  },

  /**
   * disease
   */
  getDiseaseByType(params) {
    return this.getRequest(this.path.getDiseaseByType,params)
  },
  getDiseaseDetail(params) {
    return this.getRequest(this.path.getDiseaseDetail,params)
  },
  getDiseaseMostPV(params) {
    return this.getRequest(this.path.getDiseaseMostPV,params)
  },


  getTest() {
    return this.getRequest(this.path.test)
  },

  /**
   * User
   */
  login(params) {
    return this.postRequest(this.path.login, params)
  },
  register(params) {
    return this.postRequest(this.path.register, params)
  },
  getAllUser() {
    return this.getRequest(this.path.getAllUser)
  },
  getUserInfo() {
    return this.getRequest(this.path.getUserInfo)
  },
  getAllDoctor() {
    return this.getRequest(this.path.getAllDoctor)
  },
  updUserInfo(params) {
    return this.postRequest(this.path.updUserInfo,params)
  },

  /**
   * instant message
   */
  addConversation(params){
    return this.postRequest(this.path.addConversation, params)
  },
  getConversation(params){
    return this.getRequest(this.path.getConversation, params)
  },
  sendPrivateMsg(params){
    return this.postRequest(this.path.sendPrivateMsg, params)
  },
  getPrivateMsg(params){
    return this.getRequest(this.path.getPrivateMsg,params)
  }
}

export default Service;